<template>
<el-card style="height: 40%;width: 100%">
  <div>
    <div class="warp__2BP03">
      <div class="warp__1CDpL">
        <div class="warp_l__34yS8">
          ♊&nbsp;&nbsp;<span class="work__00001">求职期望</span>
        </div>
        <div class="warp_r__1-t6m">
          <img @click="addJobExpectations(1)" class="icon_style__xOInT" alt="" src="">
          <span @click="addJobExpectations(1)">添加</span>
        </div>
      </div><br><br><br><br>
      <div v-if="status_warp_from__3BK0q===1" class="warp_from__3BK0q">
        <div class="title__12Fjr">
          <span class="title__12Fjr">{{title}}</span>
        </div>
        <form class="lg-form lg-form-horizontal lg-form-large">
          <div class="input_warp__2AFbs">
            <div class="lg-form-item fl_input_all__17UYa">
              <div class="lg-form-item-label">
                <label>期望职位</label>
              </div>
              <div class="lg-form-item-control feedback success">
                <span class="lg-input-affix-wrapper lg-input-affix-wrapper-lg">
                  <el-cascader
                    clearable
                    placeholder="请选择期望职位"
                    :props="{ value: 'id',label:'name' }"
                    style="width: 100%"
                    v-model="form.position"
                    :options="positionOptions"
                    :show-all-levels="false"
                  ></el-cascader>
                </span>
              </div>
            </div>
            <div class="input_Modal__kQfNd"></div>
          </div>
          <div class="input_warp__2AFbs">
            <div class="lg-form-item fl_input_all__17UYa">
              <div class="lg-form-item-label">
                <label>期望城市</label>
              </div>
              <div class="lg-form-item-control feedback success">
                <span class="lg-input-affix-wrapper lg-input-affix-wrapper-lg">
                  <el-cascader
                    clearable
                    placeholder="请选择期望城市"
                    :props="{ value: 'id',label:'address' }"
                    style="width: 100%"
                    v-model="form.address"
                    :options="addressOptions"
                    :show-all-levels="false"
                  ></el-cascader>
                </span>
              </div>
            </div>
            <div class="input_Modal__kQfNd"></div>
          </div>
          <div class="input_warp__2AFbs">
            <div class="lg-form-item fl_select__3zVXB">
              <div class="lg-form-item-label">
                <label>期望薪资</label>
              </div>
              <div class="lg-form-item-control feedback success">
                <el-select @change="editMoney" style="width: 48%" v-model="form.minsalary">
                  <el-option
                    v-for="item in minSalaryOptions"
                    :key="item.id"
                    :label="item.money"
                    :value="item.id">
                  </el-option>
                </el-select>&nbsp;&nbsp;&nbsp;&nbsp;
                <el-select @change="editMoney" style="width: 48%" v-model="form.maxsalary">
                  <el-option
                    v-for="item in maxSalaryOptions"
                    :key="item.id"
                    :label="item.money"
                    :value="item.id">
                  </el-option>
                </el-select><br><br>
                <el-alert
                  :closable="false"
                  v-if="alertStatus===1"
                  style="width: 99.4%"
                  title="期望薪资填写错误！"
                  type="error"
                  center
                  show-icon>
                </el-alert>
              </div>
            </div>
          </div>
          <div class="button_w__9UtkX fl_w__UKyBE">
            <div class="fl_l__297YX">
              <el-button @click="hopeJobSubmit" :disabled="buttonDisabled" class="lgButton__1UxBx lgPrimaryButton__IV-Ot">确认</el-button>
              <button class="lg-button lg-button-text fl_l__297YX work_btn_cancel__1XEeL" type="button">
                <span @click="addJobExpectations(0)">取消</span>
              </button>
            </div>
          </div>
        </form>
      </div><br><br>
      <el-card shadow="hover" v-if="hopeTableData.length!==0" v-for="(item,index) in hopeTableData" :key="index">
        <div>
          <el-link style="font-size: 20px">🧧</el-link>
          <span style="margin-left: 30px;font-size: 16px">{{editHopePositionId(item.hopePositionId,0)}}</span>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 20px">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <span style="font-size: 16px">{{editHopePositionId(item.hopeAddressId,1)}}</span>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 20px">|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <span style="font-size: 16px">{{editHopePositionId(item.hopeSalaryId,2)}}</span>

          <a style="margin-right: 50px;float: right;">
            <img style="width: 20px; height: 20px" @click="deleteHope(item.id)" class="icon_d__8fzmg" alt="" src="">
          </a>
          <a style="margin-right: 50px;float: right;">
            <img style="width: 20px; height: 20px" @click="updateHope(item)" class="icon_e__36ON5" alt="" src="">
          </a>
        </div>
      </el-card>
    </div>
  </div>
  </el-card>
</template>

<script>
export default {
  inject:['reload'],
  data () {
    return {
      title: '添加求职意向',
      alertStatus: 0,
      status_warp_from__3BK0q: 0,
      form: {
        id: '',
        minsalary: 15,
        maxsalary: 16,
        address: [],
        position: [],
        resumeId: '',
      },
      minSalaryOptions: [],//最低薪资
      maxSalaryOptions: [],//最高薪资
      addressOptions: [],//城市数据
      addressOptionsOne: [],//城市全部数据
      positionOptions: [],//职位数据,
      positionOptionsOne: [],//职位全部数据,
      buttonDisabled: false,
      hopeTableData: [],//列表数据
      dataListSelections: [],
      user: {},
      resume:{}
    }
  },
  methods: {
    deleteHope(id){//删除数据
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/resume/hope/delete'),
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message.error(data.msg)
          }
        })
        this.addJobExpectations(0)
        this.reload();
      })
    },
    updateHope(val){//修改数据
    this.addJobExpectations(1);
      this.title = '修改求职意向'
      this.form.id = val.id;
      this.form.minsalary = JSON.parse(val.hopeSalaryId)[0];
      this.form.maxsalary = JSON.parse(val.hopeSalaryId)[1];
      this.form.address = JSON.parse(val.hopeAddressId);
      this.form.position = JSON.parse(val.hopePositionId);
    },
    editHopePositionId(val,status){//数据转码
      if (status===0){
        val = JSON.parse(val);
        val = val[val.length-1];
        for (let i=0;i<this.positionOptionsOne.length;i++){
          let data = this.positionOptionsOne[i];
          if (data.id===val){
            return data.name;
          }
        }
      }
      if (status===1){
        val = JSON.parse(val);
        val = val[val.length-1];
        for (let i=0;i<this.addressOptionsOne.length;i++){
          let data = this.addressOptionsOne[i];
          if (data.id===val){
            return data.address;
          }
        }
      }
      if (status===2){
        val = JSON.parse(val);
        let resultData = '';
        let valOne = val[0];
        let valTwo = val[1];
        for (let i=0;i<this.minSalaryOptions.length;i++){
          let data = this.minSalaryOptions[i];
          if (data.id===valOne){
            resultData += data.money + "-";
          }
        }
        for (let i=0;i<this.minSalaryOptions.length;i++){
          let data = this.minSalaryOptions[i];
          if (data.id===valTwo){
            resultData += data.money;
          }
        }
        return resultData;
      }
    },
    editMoney(){//最低薪资变动
      if (this.form.minsalary>=this.form.maxsalary){
        this.alertStatus = 1;
        this.buttonDisabled = true;
      }else{
        this.alertStatus = 0;
        this.buttonDisabled = false;
      }
    },
    hopeJobSubmit(){
      if (this.form.position===''){
        this.$message.error('期望职位不能为空！');
        return;
      }
      if (this.form.address===''){
        this.$message.error('期望城市不能为空！');
        return;
      }
      if (this.hopeTableData.length===3 && this.form.id===''){
        this.$message.error('期望职位最多添加三个！');
        this.findHopeList();
        this.addJobExpectations(0)
        return;
      }
      //添加到后台
      let form = {
        id: '',
        hopeSalaryId: [],
        hopeAddressId: '',
        hopePositionId: '',
        resumeId: ''
      }
      form.id = this.form.id;
      form.hopeSalaryId.push(this.form.minsalary)
      form.hopeSalaryId.push(this.form.maxsalary)
      form.hopeSalaryId = JSON.stringify(form.hopeSalaryId)
      form.hopeAddressId = JSON.stringify(this.form.address);
      form.hopePositionId = JSON.stringify(this.form.position);
      form.resumeId = this.form.resumeId;
      this.$http({
        url: this.$http.adornUrl('/hope/positions'),
        method: 'post'
      }).then(({data}) => {
        this.positionOptions = this.editData(data)
      })

      this.$http({
        url: this.$http.adornUrl(`/resume/hope/list/${this.resume.id}`),
        method: 'get'
      }).then(({data}) => {
        this.hopeTableData = data.data
      })

      this.$http({
        url: this.$http.adornUrl(`/resume/hope/${!form.id ? 'save' : 'update'}`),
        method: 'post',
        data: this.$http.adornData({
          'id': form.id || undefined,
          'hopeSalaryId': form.hopeSalaryId,
          'hopeAddressId': form.hopeAddressId,
          'hopePositionId': form.hopePositionId,
          'resumeId': form.resumeId
        })
      }).then(({data}) => {
        if (data.msg==='success'){
          this.$message({
            message: '求职期望保存成功！',
            type: 'success',
            duration: '1200'
          });
        }else{
          this.$message.error('求职期望保存失败！');
        }
      })
      this.addJobExpectations(0)
      this.reload();
    },
    addJobExpectations (val) {//每次刷新form数据
      this.form = {
        id: '',
        minsalary: 15,
        maxsalary: 16,
        address: [],
        position: [],
        resumeId: '',
      }
      this.form.resumeId = this.resume.id;
      this.title = '添加求职意向';
      this.status_warp_from__3BK0q = val
    },
    editData(val){//处理流数据
      for (let i=0;i<val.length;i++){
        if (val[i].children.length === 0){
          val[i].children = undefined
        }else{
          this.editData(val[i].children)
        }
      }
      return val
    },
    findHopeList(){
      this.$http({
        url: this.$http.adornUrl(`/resume/hope/list/${this.resume.id}`),
        method: 'get'
      }).then(({data}) => {
        if(data.data!='') {
          this.$emit('resumTest')
          this.hopeTableData = data.data
        }
      })
    },
    async findHopeData () {
      //this.user = JSON.parse(localStorage.getItem('user'));
       this.resume= JSON.parse(localStorage.getItem("resume"));
      this.findHopeList();
      await this.$http({
        url: this.$http.adornUrl('/hope/position'),
        method: 'get'
      }).then(({data}) => {
        this.positionOptionsOne = data;
      })
      await this.$http({
        url: this.$http.adornUrl('/hope/address'),
        method: 'get'
      }).then(({data}) => {
        this.addressOptionsOne = data;
      })
      await this.$http({
        url: this.$http.adornUrl('/hope/positions'),
        method: 'get'
      }).then(({data}) => {
        this.positionOptions = this.editData(data)
      })
      await this.$http({
        url: this.$http.adornUrl('/hope/addresss'),
        method: 'get'
      }).then(({data}) => {
        this.addressOptions = this.editData(data)
      })
      await this.$http({
        url: this.$http.adornUrl('/hope/minsalary'),
        method: 'get'
      }).then(({data}) => {
        this.minSalaryOptions = data
        this.maxSalaryOptions = data
        this.maxSalaryOptions[this.maxSalaryOptions.length-1] = {id:100,money:'100k'}
      })
    }
  },
  created () {
    this.findHopeData()
  }
}
</script>

<style scoped>

  .warp__1CDpL .warp_r__1-t6m .icon_style__xOInT {
    width: 14px;
    height: 14px;
    margin-right: 5px;
    vertical-align: middle;
  }

  .warp__1CDpL .warp_r__1-t6m {
    margin-right: 50px;
    float: right;
    font-size: 14px;
    font-weight: 400;
    color: #02B28A;
    line-height: 28px;
    cursor: pointer;
  }

  .a1{
    border-left: 3px solid #00B38A;
    height: 16px;
    position: absolute;
    top: 24px;
    /*left: 30px;*/
  }

  .work__00001{
    font-size: 20px;
    font-weight: 600;
    color: #040404;
  }

  .warp_from__3BK0q {
    /*width: 780px;*/
    /*margin: 30px auto;*/
    padding: 30px 40px;
    /*padding-top: 0;*/
    background: #F8F9FB;
    border-radius: 2px;
    border: 1px dashed #E8E9EB;
  }

  .warp_from__3BK0q .title__12Fjr {
    margin: 30px 0;
    font-size: 16px;
    font-weight: 600;
    color: #00B38A;
  }

  .warp_from__3BK0q .input_warp__2AFbs {
    position: relative;
  }

  .warp_from__3BK0q .input_warp__2AFbs .fl_input_all__17UYa {
    margin-bottom: 20px;
  }

  .lg-form-item:first-child {
    margin-top: 0;
  }

  .lg-form-item {
    position: relative;
    margin-top: 22px;
  }

  .warp_from__3BK0q .input_warp__2AFbs .fl_input_all__17UYa div:first-child {
    width: 85px;
  }

  .lg-form-horizontal .lg-form-item-label {
    margin-bottom: 0;
    width: 90px;
  }

  .lg-form-horizontal .lg-form-item-label, .lg-form-horizontal .lg-form-item-control {
    display: inline-block;
  }

  .lg-form-item-label {
    margin-bottom: 10px;
    font-size: 14px;
    color: #333;
    vertical-align: top;
  }

  .lg-form-horizontal .lg-form-item-label label {
    display: block;
    height: 40px;
    line-height: 40px;
    text-align: right;
  }

  .warp_from__3BK0q .input_warp__2AFbs .fl_input_all__17UYa div:last-child {
    width: 576px;
  }

  .lg-form-horizontal .lg-form-item-control {
    width: 300px;
    margin-left: 20px;
  }

  .lg-form-horizontal .lg-form-item-label, .lg-form-horizontal .lg-form-item-control {
    display: inline-block;
  }

  .lg-form-item-control {
    position: relative;
  }

  .lg-input-affix-wrapper {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
    list-style: none;
    position: relative;
    display: inline-block;
    width: 100%;
    text-align: start;
  }

  .lg-form-item-control.feedback .lg-input {
    padding-right: 30px;
  }

  .lg-input-affix-wrapper .lg-input:not(:last-child) {
    padding-right: 30px;
  }

  .lg-input-affix-wrapper .lg-input {
    min-height: 100%;
  }

  .lg-input-affix-wrapper .lg-input {
    position: relative;
    text-align: inherit;
  }

  input[type=text], input[type=password], textarea {
    font-family: "Microsoft Yahei", "SimSun", Arial, "Helvetica Neue", Helvetica;
  }

  a, area, button, [role='button'], input:not([type='range']), label, select, summary, textarea {
    touch-action: manipulation;
  }

  input[type='text'], input[type='password'], input[type='number'], textarea {
    -webkit-appearance: none;
  }

  button, input, optgroup, select, textarea {
    margin: 0;
    padding: 0;
    border: 1px solid #ededed;
    border-radius: 0;
    font-family: "Hiragino Sans GB", "Microsoft Yahei", "SimSun", Arial, "Helvetica Neue", Helvetica;
  }

  .lg-input-affix-wrapper .lg-input-suffix {
    right: 12px;
  }

  .lg-input-affix-wrapper .lg-input-prefix, .lg-input-affix-wrapper .lg-input-suffix {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    color: #333;
    line-height: 0;
    transform: translateY(-50%);
  }

  [class^="icon-lg-"], [class*=" icon-lg-"] {
    font-family: "lagou-icon" !important;
    font-style: normal;
    font-weight: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .lg-input-affix-wrapper {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
    list-style: none;
    position: relative;
    display: inline-block;
    width: 100%;
    text-align: start;
  }

  .lg-input-affix-wrapper .lg-input-suffix {
    right: 12px;
  }

  .lg-input-affix-wrapper .lg-input-prefix, .lg-input-affix-wrapper .lg-input-suffix {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    color: #333;
    line-height: 0;
    transform: translateY(-50%);
  }

  [class^="icon-lg-"], [class*=" icon-lg-"] {
    font-family: "lagou-icon" !important;
    font-style: normal;
    font-weight: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  .warp_from__3BK0q .input_warp__2AFbs {
    position: relative;
  }

  .lg-form-item:first-child {
    margin-top: 0;
  }

  .lg-form-item {
    position: relative;
    margin-top: 22px;
  }

  .warp_from__3BK0q .input_warp__2AFbs .fl_select__3zVXB > div:first-child {
    width: 85px;
  }

  .lg-form-horizontal .lg-form-item-label {
    margin-bottom: 0;
    width: 90px;
  }

  .lg-form-horizontal .lg-form-item-label, .lg-form-horizontal .lg-form-item-control {
    display: inline-block;
  }

  .lg-form-item-label {
    margin-bottom: 10px;
    font-size: 14px;
    color: #333;
    vertical-align: top;
  }

  .lg-form-horizontal .lg-form-item-label label {
    display: block;
    height: 40px;
    line-height: 40px;
    text-align: right;
  }

  .warp_from__3BK0q .input_warp__2AFbs .fl_select__3zVXB > div:last-child {
    width: 580px;
  }

  .lg-form-horizontal .lg-form-item-control {
    width: 300px;
    margin-left: 20px;
  }

  .lg-form-horizontal .lg-form-item-label, .lg-form-horizontal .lg-form-item-control {
    display: inline-block;
  }

  .lg-form-item-control {
    position: relative;
  }

  element.style {
    width: 49%;
    margin-right: 2%;
  }

  .lg-select-lg .lg-select-selection--single {
    height: 40px;
  }

  .lg-select-lg .lg-select-selection__rendered {
    line-height: 38px;
  }

  .lg-select-selection--single .lg-select-selection__rendered {
    margin-right: 24px;
  }

  element.style {
    display: block;
    opacity: 1;
  }

  .warp_from__3BK0q .input_warp__2AFbs .lg-select-selection-selected-value {
    font-size: 16px;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  element.style {
    user-select: none;
  }

  .lg-select-arrow .lg-select-arrow-icon {
    transition: transform 0.3s;
  }

  [class^="icon-lg-"], [class*=" icon-lg-"] {
    font-family: "lagou-icon" !important;
    font-style: normal;
    font-weight: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  element.style {
    width: 49%;
  }

  .lg-select-lg .lg-select-selection--single {
    height: 40px;
  }

  .lg-select-lg .lg-select-selection__rendered {
    line-height: 38px;
  }

  .lg-select-selection--single .lg-select-selection__rendered {
    margin-right: 24px;
  }

  element.style {
    display: block;
    opacity: 1;
  }

  .warp_from__3BK0q .input_warp__2AFbs .lg-select-selection-selected-value {
    font-size: 16px;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  element.style {
    user-select: none;
  }

  .lg-select-arrow .lg-select-arrow-icon {
    transition: transform 0.3s;
  }

  [class^="icon-lg-"], [class*=" icon-lg-"] {
    font-family: "lagou-icon" !important;
    font-style: normal;
    font-weight: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  .button_w__9UtkX {
    margin-top: 20px;
    margin-left: 76px;
  }

  .myresume_container__3kIcL .fl_w__UKyBE .fl_l__297YX {
    float: left;
  }

  element.style {
    width: 88px;
  }

  .lgPrimaryButton__IV-Ot {
    background: #00b38a;
    border-radius: 2px;
    color: #ffffff;
  }

  .lgButton__1UxBx {
    width: 100px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border-radius: 2px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    cursor: pointer;
    margin-right: 10px;
  }

  .myresume_container__3kIcL .fl_w__UKyBE .fl_l__297YX {
    float: left;
  }

  button, html [type="button"], [type="reset"], [type="submit"] {
    -webkit-appearance: button;
  }

  .lg-button {
    display: inline-block;
    margin: 0;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid #c4c4c4;
    text-shadow: none;
    box-shadow: none;
    cursor: pointer;
    outline: none;
    padding: 10px 15px;
    font-size: 12px;
    border-radius: 2px;
  }

  .work_btn_cancel__1XEeL {
    height: 40px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
    margin-left: 10px;
  }

  label, select, button, input[type="button"], input[type="reset"], input[type="submit"], input[type="radio"], input[type="checkbox"], input[type="file"] {
    cursor: pointer;
  }

  button, input, optgroup, select, textarea {
    margin: 0;
    padding: 0;
    border: 1px solid #ededed;
    border-radius: 0;
    font-family: "Hiragino Sans GB", "Microsoft Yahei", "SimSun", Arial, "Helvetica Neue", Helvetica;
  }

  button, select {
    text-transform: none;
  }

  button, input {
    overflow: visible;
  }

  input, button, select, optgroup, textarea {
    margin: 0;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
    line-height: inherit;
  }

  .myresume_container__3kIcL .fl_w__UKyBE:after {
    content: '';
    height: 0;
    line-height: 0;
    display: block;
    visibility: hidden;
    clear: both;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  .lg-button-text {
    padding-left: 0;
    padding-right: 0;
    color: #00b38a;
    border-color: transparent;
    background-color: transparent;
  }

</style>
